package com.android.examplelist;



import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

public class FragmentCallbackActivity extends FragmentActivity {


	private ViewPager mViewPager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_callback);
		
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		
		mViewPager = (ViewPager) findViewById(R.id.view_pager);
		
	    PageAdapter adapter = new PageAdapter(getSupportFragmentManager());
	    mViewPager.setAdapter(adapter);
	}
	
	
	
	private static final class PageAdapter extends FragmentStatePagerAdapter {

		
		public PageAdapter(android.support.v4.app.FragmentManager fragmentManager) {
			super(fragmentManager);
		}


		@Override
		public Fragment getItem(int position) {

			CustomFragment fragment = new CustomFragment();
			return fragment;
		}

		@Override
		public int getCount() {
			return 5;
		}

	}


	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case android.R.id.home:
				finish();
				return true;
			case R.id.action_settings:
				return true;
		}
		
		return super.onOptionsItemSelected(item);
	 }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
